package com.huobao.yunying.activitys_hehuoren;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;

import org.xutils.view.annotation.ViewInject;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.huobao.yunying.base.HuobaoBaseActivity;
import com.huobao.yunying.https.Http;
import com.huobao.yunying.https.HttpListener;
import com.huobao.yunying.https.HttpUtil;
import com.huobao.zhangying.R;

import android.widget.TextView;

public class Act_Huiyuan_detail extends HuobaoBaseActivity {

	@ViewInject(R.id.tv_email)
	private TextView tv_email;
	@ViewInject(R.id.tv_tongxun)
	private TextView tv_tongxun;
	@ViewInject(R.id.tv_regtime)
	private TextView tv_regtime;
	@ViewInject(R.id.tv_lastlogin)
	private TextView tv_lastlogin;
	@ViewInject(R.id.tv_loginnum)
	private TextView tv_loginnum;
	@ViewInject(R.id.tv_name)
	private TextView tv_name;
	@ViewInject(R.id.tv_storename)
	private TextView tv_storename;
	@ViewInject(R.id.tv_store_address)
	private TextView tv_store_address;

	private String user_id;

	@Override
	protected int getContentView() {
		// TODO Auto-generated method stub
		return R.layout.layout_huiyuan_detail;
	}

	@Override
	protected String getTitleText() {
		// TODO Auto-generated method stub
		return "会员详情";
	}

	@Override
	protected void init() {
		user_id = getIntent().getStringExtra("user_id");
		getDetail();
	}

	private void getDetail() {
		Map<String, String> map = HttpUtil.getParams("app", "partner", "act", "membershow", "userid", user_id);
		Http.getInstant().sendRequest(context, map, new HttpListener() {

			@Override
			public void onHttpSuccess(String result) {
				JSONObject jsonObject = JSON.parseObject(result);
				jsonObject = jsonObject.getJSONObject("retval");
				tv_email.setText(jsonObject.getString("email"));
				String qq = jsonObject.getString("im_qq");
				if(qq == null || qq.equals("") || qq.equals("null")){
					tv_tongxun.setText("QQ:" + " " + "\n手机：" + jsonObject.getString("phone_mob"));	
				}else{
					tv_tongxun.setText("QQ:" + jsonObject.getString("im_qq") + "\n手机：" + jsonObject.getString("phone_mob"));
				}
				
				tv_regtime.setText(new SimpleDateFormat("yyyy-MM-dd")
						.format(new Date(jsonObject.getLongValue("reg_time") * 1000)));
				String last_login = jsonObject.getString("last_login");
				if (last_login != null && last_login.equals("null") == false && last_login.equals("") == false) {
					tv_lastlogin.setText(new SimpleDateFormat("yyyy-MM-dd")
							.format(new Date(jsonObject.getLongValue("last_login") * 1000)));
				} else {
					tv_lastlogin.setText("");
				}

				tv_loginnum.setText(jsonObject.getString("logins"));
				tv_name.setText(jsonObject.getString("real_name"));
				tv_storename.setText(jsonObject.getString("shop_name"));
				tv_store_address.setText(jsonObject.getString("maddress"));
			}

			@Override
			public void onHttpError(String error) {
				// TODO Auto-generated method stub

			}
		});
	}

}
